home *** CD-ROM | disk | FTP | other *** search
/ Champak Vol A-4 / (Vol A-4) Vol. A4.iso / Games / the_fighter_training.swf / scripts / frame_29 / DoAction.as
Text File  |  2008-03-13  |  5KB  |  258 lines

  1. function init()
  2. {
  3.    gameMode = "ready";
  4.    score = 0;
  5.    setMeter(score_mc,score);
  6.    item_array = new Array();
  7.    point_array = new Array(100,120,140,200);
  8.    interval = 30;
  9.    bg_sound.start();
  10. }
  11. function setMeter(meter, num)
  12. {
  13.    var _loc2_ = String(num);
  14.    meter.gotoAndStop(_loc2_.length);
  15.    var _loc3_ = 0;
  16.    var _loc1_ = _loc2_.length - 1;
  17.    while(_loc1_ >= 0)
  18.    {
  19.       meter["n" + _loc3_].gotoAndStop(Number(_loc2_.charAt(_loc1_)) + 1);
  20.       _loc3_ = _loc3_ + 1;
  21.       _loc1_ = _loc1_ - 1;
  22.    }
  23. }
  24. function goPunch(tLabel, tNum)
  25. {
  26.    if(gameMode == "ing")
  27.    {
  28.       if(tLabel == "away")
  29.       {
  30.          if(char_mc.char_mode != "down")
  31.          {
  32.             char_mc.gotoAndPlay(tLabel + tNum);
  33.          }
  34.       }
  35.       else if(char_mc.char_mode == "base")
  36.       {
  37.          char_mc.gotoAndPlay(tLabel + tNum);
  38.       }
  39.    }
  40. }
  41. function removeItem(mc)
  42. {
  43.    mc.removeMovieClip();
  44.    item_array.shift();
  45. }
  46. function removeItemAll()
  47. {
  48.    var _loc1_ = 0;
  49.    while(_loc1_ < item_array.length)
  50.    {
  51.       var _loc2_ = item_array.pop();
  52.       _loc2_.removeMovieClip();
  53.       _loc1_ = _loc1_ + 1;
  54.    }
  55. }
  56. function charDown()
  57. {
  58.    char_mc.char_mode = "down";
  59.    char_mc.gotoAndPlay("down");
  60.    removeItemAll();
  61.    delete this.onEnterFrame;
  62.    var _loc2_ = 12 - int(energy_mc._currentframe / 10);
  63.    setPowerGage(_loc2_);
  64. }
  65. function charGetUp()
  66. {
  67.    delete gage_mc.onEnterFrame;
  68.    char_mc.gotoAndPlay("up");
  69.    ctrlEnergy(5);
  70.    gameStart();
  71. }
  72. function gameOver()
  73. {
  74.    gameMode = "over";
  75.    removeItemAll();
  76.    delete gage_mc.onEnterFrame;
  77.    delete this.onEnterFrame;
  78. }
  79. function genItem(mc)
  80. {
  81.    var _loc2_ = random(5);
  82.    var _loc3_ = mc.getNextHighestDepth();
  83.    var _loc1_ = undefined;
  84.    if(_loc2_ < 4)
  85.    {
  86.       _loc1_ = item_mc.duplicateMovieClip("item" + _loc3_,_loc3_);
  87.       item_array.push(_loc1_);
  88.       if(_loc2_ == 3)
  89.       {
  90.          _loc1_.life = 2;
  91.       }
  92.       else
  93.       {
  94.          _loc1_.life = 1;
  95.       }
  96.       _loc1_.itemNum = _loc2_;
  97.       _loc1_.gotoAndStop(2 + _loc2_);
  98.    }
  99.    else if(random(5) == 0)
  100.    {
  101.       removeItemAll();
  102.       item5.play();
  103.    }
  104. }
  105. function ctrlEnergy(arg)
  106. {
  107.    if(arg < 0)
  108.    {
  109.       var _loc1_ = 0;
  110.       while(_loc1_ < - arg)
  111.       {
  112.          energy_mc.nextFrame();
  113.          _loc1_ = _loc1_ + 1;
  114.       }
  115.    }
  116.    else if(arg > 0)
  117.    {
  118.       _loc1_ = 0;
  119.       while(_loc1_ < arg)
  120.       {
  121.          energy_mc.prevFrame();
  122.          _loc1_ = _loc1_ + 1;
  123.       }
  124.    }
  125. }
  126. function downGage()
  127. {
  128.    gage_mc.sub.prevFrame();
  129. }
  130. function upGage(mc)
  131. {
  132.    if(gage_mc._currentframe > 1)
  133.    {
  134.       gage_mc.sub.nextFrame();
  135.    }
  136. }
  137. function setPowerGage(arg)
  138. {
  139.    var incNum = 0;
  140.    gage_mc.play();
  141.    gage_mc.onEnterFrame = function()
  142.    {
  143.       incNum++;
  144.       if(incNum % arg == 0)
  145.       {
  146.          downGage();
  147.       }
  148.    };
  149. }
  150. function gameStart()
  151. {
  152.    gameMode = "ing";
  153.    var incNum = 0;
  154.    this.onEnterFrame = function()
  155.    {
  156.       incNum++;
  157.       if(incNum % interval == 0)
  158.       {
  159.          genItem(this);
  160.          incNum = 0;
  161.          interval = 28 + random(10);
  162.       }
  163.    };
  164. }
  165. var hit1_sound = new Sound();
  166. hit1_sound.attachSound("hit1");
  167. var hit2_sound = new Sound();
  168. hit2_sound.attachSound("hit2");
  169. var hit3_sound = new Sound();
  170. hit3_sound.attachSound("hit3");
  171. var bg_sound = new Sound(bg_mc);
  172. bg_sound.attachSound("bgm");
  173. bg_sound.setVolume(50);
  174. bg_sound.onSoundComplete = function()
  175. {
  176.    bg_sound.start();
  177. };
  178. var keyLst = new Object();
  179. var KL = false;
  180. var KR = false;
  181. var KU = false;
  182. var KD = false;
  183. var KS = false;
  184. keyLst.onKeyDown = function()
  185. {
  186.    var _loc1_ = "";
  187.    var _loc2_ = 0;
  188.    var _loc3_ = Key.getCode();
  189.    switch(_loc3_)
  190.    {
  191.       case 38:
  192.          if(!KU)
  193.          {
  194.             _loc1_ = "hitUp";
  195.             _loc2_ = random(2);
  196.             goPunch(_loc1_,_loc2_);
  197.             KU = true;
  198.          }
  199.          break;
  200.       case 40:
  201.          if(!KD)
  202.          {
  203.             _loc1_ = "hitDown";
  204.             _loc2_ = random(2);
  205.             goPunch(_loc1_,_loc2_);
  206.             KD = true;
  207.          }
  208.          break;
  209.       case 37:
  210.          if(!KL)
  211.          {
  212.             _loc1_ = "away";
  213.             _loc2_ = random(2);
  214.             goPunch(_loc1_,_loc2_);
  215.             KL = true;
  216.          }
  217.          break;
  218.       case 39:
  219.          if(!KR)
  220.          {
  221.             _loc1_ = "hitMid";
  222.             _loc2_ = random(2);
  223.             goPunch(_loc1_,_loc2_);
  224.             KR = true;
  225.          }
  226.          break;
  227.       case 32:
  228.          if(!KS)
  229.          {
  230.             KS = true;
  231.             upGage();
  232.          }
  233.    }
  234. };
  235. keyLst.onKeyUp = function()
  236. {
  237.    var _loc1_ = Key.getCode();
  238.    switch(_loc1_)
  239.    {
  240.       case 38:
  241.          KU = false;
  242.          break;
  243.       case 40:
  244.          KD = false;
  245.          break;
  246.       case 37:
  247.          KL = false;
  248.          break;
  249.       case 39:
  250.          KR = false;
  251.          break;
  252.       case 32:
  253.          KS = false;
  254.    }
  255. };
  256. Key.addListener(keyLst);
  257. init();
  258.